<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>客户银行账号信息</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>

<body class="iframeBody">
    <div class="Wrapper">
        <div class="sqPanel">
            <div class="sqPanel_head inL">
                <div class="btnsBox inLC">
                    <span id="cust_cst_np_bank_acc_add_btn_id" class="sq-button sq-button-round">添加</span>
                </div>
                <span>银行账号</span>
            </div>
            <div class="sqPanel_body">
                <div id="ligergrid_bankacc" class="sq-grid"></div>
            </div>
        </div>
    </div>
 	<!-- hide data -->
	<div class="fieldBox col_100" style="display:none;">
		<div class="field">
		    <input name=cstId id="cstId" type="text" class="ui-textbox" value="${cstId}">
		</div>
	</div>
    
    
    
	<!-- 验证状态窗口-->
	<div id="div_bank_valid_id" style="display:none">
		<form id="div_bank_valid_form">
            <div class="fieldset1 tabel_col tabel_col_s clearFix noBorder">
			    <div class="fieldBox col_50">
			         <div class="label">验证状态</div>
			         <div class="field">
			               <select ligerui="width:120" name="validSts" id="win_bank_valid_sts_id" data-value="" validate="{required:true, select: true}">
		                        <c:forEach items="${validStsList }" var="vs" begin="0" step="1" varStatus="status">
				                     <c:if test="${status.index == 0}">
										 <option value="${vs.key }" selected>${vs.value }</option>
									 </c:if>
									 <c:if test="${status.index != 0}">
										 <option value="${vs.key }" >${vs.value }</option>
									 </c:if>
		                        </c:forEach>
		                    </select>
			              <span class="requiredSymbol">*</span>
			         </div>
			   </div>
			 <div class="fieldBox col_100">
			      <div class="label">备注</div>
			      <div class="field">
			          <textarea name="accRem" id="accRem" rows="4" class="l-textarea" style="width:99%" validate="{maxlength:150}"></textarea>
			      </div>
			 </div>
			 </div>
        </form>
	</div>
	
	<!-- 是否代扣卡设置窗口-->
	<div id="div_bank_deduct_id" style="display:none">
		<form id="div_bank_deduct_form">
            <div class="fieldset1 tabel_col tabel_col_s clearFix noBorder">
			   <div class="fieldBox col_50">
                    <div class="label">是否代扣卡</div>
                    <div class="field">
					 <c:forEach items="${searchSelectYesOrNoList }" var="kv" begin="0" step="1" varStatus="status">
	           			<c:if test="${kv.key == 0}">
	           				<input type="radio" value="${kv.key }" name="isDeduct" id="isDeductYes" checked />${kv.value }	
	           			</c:if>
	        	    	<c:if test="${kv.key != 0}">
	                       	<input type="radio" value="${kv.key }" name="isDeduct" id="isDeductNo"/>${kv.value }	
	                    </c:if>
	   				 </c:forEach>
	                 </div>
               </div>
			 </div>
        </form>
	</div>

    <script>
    $(function() {
    	initForm();
    	initGrid();
        initEvent();
    });
    
    //初始化Form
    function initForm(){
		$("#div_bank_valid_form").ligerForm({
         	 validate: true
  		});
		
		$("#div_bank_deduct_form").ligerForm({
        	 validate: true
 		});
    }
    
    //初始化列表
    function initGrid(){
    	var _cstId = $("#cstId").val();

        $("#ligergrid_bankacc").ligerGrid({
            usePager: false,
            url: "<%=path%>/customer/cstbank/initList.do?cstId="+_cstId+"&isEncrypt=1",
            method : 'get',
            columns: [{
                display: '开户银行',
                name: 'bkCdNm',
                width: 150,
                align:'left'
            }, {
                display: '开户机构',
                name: 'accOrgNm',
                width: 150,
                align:'left'
            }, 
            	getGridOperColumnContent4()
            , {
                display: '银行账号',
                name: 'accNo',
                minWidth: 150,
                align:'left'
            }, {
                display: '账户类型',
                name: 'accTypCdNm',
                minWidth: 100
            }, 
            	getGridOperColumnContent5()
            , 
            	getGridOperColumnContent6()
            , 
            	getGridOperColumnContent1()
            ,{
                display: '是否机构绑卡',
                name: 'isInsBindNm',
                width: 80,
            }	
            ,{
                display: '开户行行号',
                name: 'bkNo',
                width: 150,
                align:'left'
            }
            , getGridOperColumnContent2(),
            getGridOperColumnContent7(),
            getGridOperColumnContent8(),
            getGridOperColumnContent9(),
            /* , getGridOperColumnContent3() */
            ,getGridOperColumnContent()],
            width: '100%',
            //isScroll: false,
            height:'100%',
			heightDiff:-2,
            root:'rows',
	        record:'total',
            rownumbers: true,
            fixedCellHeight: false,
            usePagerOnLessPagesize: false,
            onAfterShowData: function(currentData) {
                SetIframe_height();
                $(".liger_tip").ligerTip();
            }
        });

        cstBankGrid = liger.get("ligergrid_bankacc");
        cstBankGrid.setHeight(100);
        cstBankGrid.options.isSingleCheck=true;
    }
    
    function getGridOperColumnContent1(){
    	return {
            display: '是否代扣卡',
            name: 'isDeductNm',
            width: 70
        };
    }
    
    function getGridOperColumnContent2(){
    	return {
            display: '状态',
            name: 'audStsCdNm',
            width: 120,
            render: function (rowdata, rowindex, value){
            	if(StringUtils.isNotEmpty(rowdata.audStsCdRem)){
            		value = value + "("+rowdata.audStsCdRem+")";
            	}
            	return UIUtils.showColumnTip(value);
            }
        };
    }
    
    function getGridOperColumnContent3(){
    	return {
            display: '备注',
            name: 'accRem',
            width: 200,
            render: function (rowdata, rowindex, value){
            	if(StringUtils.isEmpty(value)){//排除非空字段
            		value = "";
            	}
                var h='<span class="gridTip" title="'+ value +'">'+ value +'</span>'
                return h;
            }

        };
    }
    
    function getGridOperColumnContent4(){
    	return {
            display: '开户名称',
            name: 'accNm',
            minWidth: 150,
            align:'left',
            render: function (rowdata, rowindex, value, column) { 
        		var h = '';
    		    h='<a  href="javascript:showDetail(';
                h+="'"+rowdata.id+"'";
                h+=')">'+value+'</a>'
                return h;
    		}
        };
    }
    
    function getGridOperColumnContent5(){
    	return {
            display: '开户证件类型',
            name: 'certTypCdNm',
            width: 100
        };
    }
    
    function getGridOperColumnContent6(){
    	return {
            display: '证件号',
            name: 'certNo',
            minWidth: 150,
            align:'left'
        };
    }
    
    function getGridOperColumnContent7(){
    	return {
            display: '帐号来源',
            name: 'regWayCdNm',
            minWidth: 120,
            align:'left'
        };    	
    }
    
	function getGridOperColumnContent8(){
    	return {
            display: '签约号',
            name: 'signNo',
            minWidth: 120,
            align:'left'
        };    	
    }
    
	function getGridOperColumnContent9(){
    	return {
            display: '银行卡类型',
            name: 'cardTypeNm',
            minWidth: 120,
            align:'left'
        };		
	}
    
    //初始化事件
    function initEvent(){
    	
    	//新增银行账号事件
        $("#cust_cst_np_bank_acc_add_btn_id").click(function(event) {
            //如果客户ID不存在是不能新增的
        	var _cstId = $("#cstId").val();
        	if(!_cstId){
        		UIUtils.alertWarning(LogUtils.LOG_CUST_CONFIRM_HERE_HAS_INFO);
                return; //验证不通过，不执行以下代码
        	}
        	addBank(_cstId);
        });
        
    }
    
    
    //客户银行新增页面地址,这个地址变量不要随意改动,会有其它页面引入次页面替换URL
    var cstBankAddPageUrl = "<%=path%>/customer/cstbank/toAddPage.do";
    function addBank(_cstId){
    	$.ligerDialog.SQopen({
            width: 800,
            height:210,
            title : '银行账号',
            url:cstBankAddPageUrl+'?cstId='+_cstId,
            // 自定义buttons的时候 不要设置 fixButtons: true
            buttons: [{
                    text: "保存", type: 'ok', cls: 'l-dialog-btn-ok', 
                    onclick: function (item, Dialog) {
                        //在子页面里绑定 frameElement.dialog.onOk = function () {}
                        if (Dialog.onOk) Dialog.onOk();
                    }
                }, {
                    text: "取消", type: 'cancel', cls: 'l-dialog-btn-no', 
                    onclick: function (item, Dialog) {
                        //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                        if (Dialog.onCancel) Dialog.onCancel();
                    }
                }
            ]
        });
    }
    
  	//验证事件
	function validRow(_id, _bkCd) {
    	//如果客户ID不存在是不能修改
    	var _cstId = $("#cstId").val();
    	if(!_cstId){
    		UIUtils.alertWarning(LogUtils.LOG_CUST_CONFIRM_HERE_HAS_INFO);
            return; //验证不通过，不执行以下代码
    	}
		
		if(_bkCd == CustomerConstant.CST_BK_CD_POST){
			UIUtils.alertWarning(LogUtils.LOG_CUST_NO_VALID_CARD);
			return;
		}
		
		$("#accRem").val("");
		
        $.ligerDialog.SQopen({
            width: 800,
            height:200,
            title : '银行账号验证',
            target: $("#div_bank_valid_id"),
            buttons: [
                      {
                          text: "验证", cls: 'l-dialog-btn-ok', onclick:function(){
                          	modifyValidSts(_id, _bkCd);
                          }
                      }, {
                          text: "取消", cls: 'l-dialog-btn-no', onclick:function(){
                          	$.ligerDialog.hide();
                          }
                      }
                  ]

        });
	}
    
	//客户银行新增页面地址,这个地址变量不要随意改动,会有其它页面引入次页面替换URL
    var cstBankModifyPageUrl = "<%=path%>/customer/cstbank/toAddPage.do";
    //银行账号修改
    function modifyRow(_id){
        	//如果客户ID不存在是不能修改
        	var _cstId = $("#cstId").val();
        	if(!_cstId){
        		UIUtils.alertWarning(LogUtils.LOG_CUST_CONFIRM_HERE_HAS_INFO);
                return; //验证不通过，不执行以下代码
        	}
        	
            $.ligerDialog.SQopen({
                width: 800,
                height:210,
                title : '银行账号',
                url:cstBankModifyPageUrl+'?cstId='+_cstId+'&cbId='+_id,
                // 自定义buttons的时候 不要设置 fixButtons: true
                buttons: [
                          {
		                    text: "保存", type: 'ok', cls: 'l-dialog-btn-ok', 
		                    onclick: function (item, Dialog) {
                            //在子页面里绑定 frameElement.dialog.onOk = function () {}
                        	if (Dialog.onOk) Dialog.onOk();
	                    	}
		                 }, 
		                 {
		                    text: "取消", type: 'cancel', cls: 'l-dialog-btn-no', 
		                    onclick: function (item, Dialog) {
		                        //在子页面里绑定 frameElement.dialog.onCancel = function () {}
		                        if (Dialog.onCancel) Dialog.onCancel();
		                    }
		                }
                ]
            });
    }
    	
    
    //修改验证状态
    function modifyValidSts(_id, _bkCd){
    	 var ligerForm = liger.get("div_bank_valid_form");
    	 var data = ligerForm.getData();
    	 var _url = "<%=path%>/customer/cstbank/modifyValidSts.do";
    	 data["id"] = _id;
    	 data["bkCd"] = _bkCd;
    	 AjaxUtils.ajaxPost(_url, data, modifyValidStsCallback);
    }
    
    //修改验证状态回调
    function modifyValidStsCallback(data){
    	if(data.success == 1){
    		$.ligerDialog.hide();
    		UIUtils.alertSuccess(data.info);
    		var cstId = $("#cstId").val();
    		cstBankGrid.setParm("cstId",cstId);
			cstBankGrid.reload();
		 }else{
			UIUtils.alertError(data.info);
		 }
    }
    
    //查看详情
    var showDetailUrl = "<%=path%>/customer/cstbank/toDetailPage.do";//地址单独作为变量处理,在法人页面查看详情会替换这个地址。不能随意改变
    function showDetail(_id){
    	$.ligerDialog.SQopen({
            width: 800,
            height:220,
            title : '银行账号',
            url:showDetailUrl+'?cbId='+_id,
            // 自定义buttons的时候 不要设置 fixButtons: true
            buttons: [{
                    text: "关闭", type: 'cancel',
                    onclick: function (item, Dialog) {
                        //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                        if (Dialog.onCancel) Dialog.onCancel();
                    }
                }
            ]
        });
    }
    
    //获取Grid操作列内容
    function getGridOperColumnContent(){
    	 var data = {
            display: '操作',
            isSort: false,
            width: 260,
            align:'left',
            render: function (rowdata, rowindex, value){
            	//这里如果客户是审核通过的则不显示修改和删除按钮
                var h="";
                if(rowdata.regWayCd != '11003'){
            		if(rowdata.isOper == true){
            			h+='<a class="sq-button-hasicon" alt="修改" href="javascript:modifyRow(';
                        h+="'"+rowdata.id+"'";
                        h+=",'ligergrid_bankacc'";
                        h+=")\"><i class=\"sqBtnIco_4\"></i>"+LogUtils.LOG_CMM_GRID_BTN_MODIFY+"</a>";
            		}
                    
            		/* if(rowdata.bkCd != CustomerConstant.CST_BK_CD_POST){
            			 h+='<a class="sq-button-hasicon" alt="验证" href="javascript:validRow(';
                         h+="'"+rowdata.id+"'";
                         h+=",'"+rowdata.bkCd+"'";
                         h+=",'ligergrid_bankacc'";
                         h+=")\"><i class=\"sqBtnIco_38\"></i>"+LogUtils.LOG_CMM_GRID_BTN_VALID+"</a>";
            		} */
                    
                    h+='<a class="sq-button-hasicon" alt="是否代扣卡" href="javascript:setDeductRow(';
                    h+="'"+rowdata.id+"'";
                    h+=",'"+rowdata.isDeduct+"'";
                    h+=",'ligergrid_bankacc'";
                    h+=")\"><i class=\"sqBtnIco_30\"></i>" + LogUtils.LOG_CUST_GRID_IS_DEDUCT + "</a>";
                    
                    if(rowdata.isOper == true){
	                    h+='<a class="sq-button-hasicon" alt="删除" href="javascript:deleteBankRow(';
	                    h+="'"+rowdata.id+"'";
	                    h+=",'ligergrid_bankacc'";
	                    h+=")\"><i class=\"sqBtnIco_7\"></i>"+LogUtils.LOG_CMM_GRID_BTN_DELETE+"</a>";
                    }
                }
                if(rowdata.isInsBind == 0){
					h+='<a class="sq-button-hasicon" alt="浙商绑卡" href="javascript:openSendMsgCodePage(';
					h+="'"+rowdata.id+"'";
					h+=")\"><i class=\"sqBtnIco_4\"></i>" + LogUtils.LOG_CUST_GRID_CZBANK_BIND + "</a>";
				}
                return h;
            }
    	 }
    	return data;
    }
    
    //设置代扣卡
    function setDeductRow(_id, _isDeduct){
    	//如果客户ID不存在是不能修改
    	var _cstId = $("#cstId").val();
    	if(!_cstId){
    		UIUtils.alertWarning(LogUtils.LOG_CUST_CONFIRM_HERE_HAS_INFO);
            return; //验证不通过，不执行以下代码
    	}
    	
    	var form = new liger.get("div_bank_deduct_form");
    	$("input[name=isDeduct][value='"+_isDeduct+"']").prev().click();
		
        $.ligerDialog.SQopen({
            width: 500,
            height:100,
            title : '设置代扣卡',
            target: $("#div_bank_deduct_form"),
            buttons: [
                      {
                          text: "保存", cls: 'l-dialog-btn-ok', onclick:function(){
                          	modifyIsDeduct(_id, _isDeduct);
                          }
                      }, {
                          text: "取消", cls: 'l-dialog-btn-no', onclick:function(){
                          	$.ligerDialog.hide();
                          }
                      }
                  ]

        });
    }
    
    //修改是否代扣卡
    function modifyIsDeduct(_id, _isDecuctOld){
    	var ligerForm = liger.get("div_bank_deduct_form");
        if (!ligerForm.valid()) {
            UIUtils.alertWarning(LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO);
            return false; //验证不通过，不执行以下代码
        }
        var data = ligerForm.getData();
        var isDeduct = $('input[name="isDeduct"]:checked').val();
        data["isDeduct"] = isDeduct;
        //var isDefDeduct = $('input[name="isDefDeduct"]:checked ').val();//暂时和是否划扣卡相同
        data["isDefDeduct"] = isDeduct;
        data["id"] = _id;
        data["isDecuctOld"] = _isDecuctOld;
        
        if(isDeduct == _isDecuctOld){
        	 UIUtils.alertWarning("未变动数据不做处理.");
             return false;
        }
        
    	var _url = "<%=path%>/customer/cstbank/modifyIsDeduct.do";
    	AjaxUtils.ajaxPost(_url, data, function(msg){
    		if(msg.success == 1){
    			var cstId = $("#cstId").val();
				 UIUtils.alertSuccess(msg.info);
				 cstBankGrid.setParm("cstId",cstId);
				 cstBankGrid.reload();
				 $.ligerDialog.hide();
			 }else{
				 UIUtils.alertError(msg.info);
			 }
    	}, true);
    }
    
    //文件上传 依赖ajaxfileupload.js插件
    function uploadFile(fileElementId) {
        var url = "/xx/xxx/xxxxxxxx/xxxxxxx";
        var dialogWait = null;
        try {
            $.ajaxFileUpload({
                url: url,
                secureuri: false,
                fileElementId: fileElementId, //文件选择框的id属性
                success: function (data, textStatus) {//, textStatus
                    dialogWait.close();
                    $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_UL_SUCC, SQ_type: "success"});
                },
                before: function (f) {
                    dialogWait=$.ligerDialog.waitting(LogUtils.LOG_CMM_DATA_LOADING);
                },
                error: function (data) {
                    $.ligerDialog.SQalert({content: data,SQ_type: "error"});
                }
            });
        } catch (error) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_UL_FAIL, SQ_type: "error"});
        }
    }
    
    //删除客户开户账号信息
    function deleteBankRow (cbId, gridId) {
    	var cstId = $("#cstId").val();
    	if(!cstId){
    		$.ligerDialog.SQalert({content: LogUtils.LOG_CUST_ID_NOT_EMPTY, SQ_type: "warning"});
    		return;
    	}
    	$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
			if(flag == false)return;
			var wait_dialog= $.ligerDialog.SQalert({
	            content: LogUtils.LOG_CMM_LOADING,
	            SQ_type: "waitting",
	            onClose: function () {
	            }
	        });
			$.ajax({
	     		type: 'post',
	     		dataType:'json',
	     		data:{id:cbId},
	     		url: '<%=path%>/customer/cstbank/removeById.do',
	     		success:function(msg){
	     			 wait_dialog.close();
	     			 if(msg.success == 1){
	     				UIUtils.alertSuccess(msg.info);
	     				cstBankGrid.setParm("cstId",cstId);
	     				cstBankGrid.reload();
	     			 }else{
	     				UIUtils.alertWarning(msg.info);
	     			 }
	     		}
	     	});
		});
    }
    
	//弹出获取验证码页面
    function openSendMsgCodePage(bankid) {
        var _cstId = $("#cstId").val();
        if(StringUtils.isEmpty(_cstId)){
			$.ligerDialog.SQalert({content:"客户id为空", SQ_type: "warning"});
			return;
		}
		if(StringUtils.isEmpty(bankid)){
			$.ligerDialog.SQalert({content:"绑卡id为空", SQ_type: "warning"});
			return;
		}
        $.ligerDialog.open({
            title: '验证码换帮卡',
            height: 300,
            width: 850,
            url: '<%=path%>/institution/cstCzbank/showSendMsgCodePage.do?cstId=' + _cstId + '&bankId=' + bankid
        });


    }


    
    </script>
</body>

</html>
